<template>
    <div>
        <div><h1>商户列表</h1></div>
        <div>
            <el-table :data="tableData" stripe style="width: 100%">
                <el-table-column prop="userId" label="ID" width="100" />
                <el-table-column prop="userName" label="昵称" width="180" />
                <el-table-column prop="userMobile" label="手机号" width="180" />
                <el-table-column prop="userEmail" label="邮箱" width="180" />
                <el-table-column prop="userGender" label="性别" width="180" />
                <el-table-column prop="userAvatar" label="头像" width="180" />
                <el-table-column
                    prop="createTime"
                    label="注册时间"
                    width="180"
                />
                <el-table-column label="操作" />
            </el-table>
        </div>
        <div style="margin-top: 20px;">
            <el-pagination
                v-model:current-page="searchForm.pageNum"
                v-model:page-size="searchForm.pageSize"
                :page-sizes="[2, 4, 6, 8]"
                :background="true"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
            />
        </div>
    </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from "vue";
import { getShopperList } from "../api/api";

const tableData = ref([]);
const searchForm = ref({
    pageNum: 1,
    pageSize: 2,
});
const total = ref(0);

const handleSizeChange = (val: number) => {
  console.log(`${val} items per page`);
  searchForm.value.pageSize = val;
  loadList();
}
const handleCurrentChange = (val: number) => {
  console.log(`current page: ${val}`);
  searchForm.value.pageNum = val;
  loadList();
}

const loadList = () => {
    getShopperList(searchForm.value).then((res: any) => {
        tableData.value = res.data.data.records;
        total.value = res.data.data.total;
    });
};

// 页面加载钩子函数
onMounted(() => {
    loadList();
});
</script>

<style scoped></style>
